package com.xia.manager.error;

/**
 * @ClassName ErrorEnum
 * @Deserintion 错误种类
 * @Author ciyuan
 * @Date 2018/11/25/025 16:18
 **/
public enum ErrorEnum {
    /**
     * 产品编号为空
     */
    ID_NOT_NULL("F001","编号不可为空",false),
    //...
    /**
     * 未知异常
     */
    UNKNOW("-1","未知异常",false)
    ;
    /**
     * 异常编码
     */
    private String code;
    /**
     * 异常描述
     */
    private String message;
    /**
     * 能否重试
     */
    private boolean canRetry;

    ErrorEnum(String code, String message, boolean canRetry) {
        this.code = code;
        this.message = message;
        this.canRetry = canRetry;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public boolean isCanRetry() {
        return canRetry;
    }

    public void setCanRetry(boolean canRetry) {
        this.canRetry = canRetry;
    }

    public static ErrorEnum getByCode(String code){
        for (ErrorEnum errorEnum : ErrorEnum.values()) {
            if (errorEnum.code.equals(code)) {
                return errorEnum;
            }
        }
        return UNKNOW;
    }
}
